...and pass `-C overflow-checks` to the compiler when necessary.
Fixes #2262.
pub rustdoc_args: Option<Vec<String>>,
pub debuginfo: Option<u32>,
pub debug_assertions: bool,
+ pub overflow_checks: bool,
#[serde(skip_serializing)]
pub rpath: bool,
pub test: bool,
Profile {
debuginfo: Some(2),
debug_assertions: true,
+ overflow_checks: true,
..Profile::default()
}
}
rustdoc_args: None,
debuginfo: None,
debug_assertions: false,
+ overflow_checks: false,
rpath: false,
test: false,
doc: false,
crate_types: &[&str]) {
let Profile {
ref opt_level, lto, codegen_units, ref rustc_args, debuginfo,
- debug_assertions, rpath, test, doc: _doc, run_custom_build,
- ref panic, rustdoc_args: _, check,
+ debug_assertions, overflow_checks, rpath, test, doc: _doc,
+ run_custom_build, ref panic, rustdoc_args: _, check,
} = *unit.profile;
assert!(!run_custom_build);
cmd.args(args);
}
- if debug_assertions && opt_level != "0" {
- cmd.args(&["-C", "debug-assertions=on"]);
- } else if !debug_assertions && opt_level == "0" {
- cmd.args(&["-C", "debug-assertions=off"]);
+ // -C overflow-checks is implied by the setting of -C debug-assertions,
+ // so we only need to provide -C overflow-checks if it differs from
+ // the value of -C debug-assertions we would provide.
+ if opt_level != "0" {
+ if debug_assertions {
+ cmd.args(&["-C", "debug-assertions=on"]);
+ if !overflow_checks {
+ cmd.args(&["-C", "overflow-checks=off"]);
+ }
+ } else if overflow_checks {
+ cmd.args(&["-C", "overflow-checks=on"]);
+ }
+ } else {
+ if !debug_assertions {
+ cmd.args(&["-C", "debug-assertions=off"]);
+ if overflow_checks {
+ cmd.args(&["-C", "overflow-checks=on"]);
+ }
+ } else if !overflow_checks {
+ cmd.args(&["-C", "overflow-checks=off"]);
+ }
}
if test && unit.target.harness() {
debug_assertions: Option<bool>,
rpath: Option<bool>,
panic: Option<String>,
+ #[serde(rename = "overflow-checks")]
+ overflow_checks: Option<bool>,
}
#[derive(Clone, Debug)]
fn merge(profile: Profile, toml: Option<&TomlProfile>) -> Profile {
let &TomlProfile {
ref opt_level, lto, codegen_units, ref debug, debug_assertions, rpath,
- ref panic
+ ref panic, ref overflow_checks,
} = match toml {
Some(toml) => toml,
None => return profile,
rustdoc_args: None,
debuginfo: debug.unwrap_or(profile.debuginfo),
debug_assertions: debug_assertions.unwrap_or(profile.debug_assertions),
+ overflow_checks: overflow_checks.unwrap_or(profile.overflow_checks),
rpath: rpath.unwrap_or(profile.rpath),
test: profile.test,
doc: profile.doc,
"debug_assertions": true,
"debuginfo": 2,
"opt_level": "0",
+ "overflow_checks": true,
"test": false
},
"features": [],
"debug_assertions": true,
"debuginfo": 2,
"opt_level": "0",
+ "overflow_checks": true,
"test": false
},
"features": [],
"debug_assertions": true,
"debuginfo": 2,
"opt_level": "0",
+ "overflow_checks": true,
"test": false
},
"features": [],
"debug_assertions": true,
"debuginfo": 2,
"opt_level": "0",
+ "overflow_checks": true,
"test": false
},
"features": [],
"debug_assertions":true,
"debuginfo":2,
"opt_level":"0",
+ "overflow_checks": true,
"test":false
},
"features":[],
"));
}
+#[test]
+fn cargo_test_overflow_checks() {
+ if !is_nightly() {
+ return;
+ }
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "foo"
+ version = "0.5.0"
+ authors = []
+
+ [[bin]]
+ name = "foo"
+
+ [profile.release]
+ overflow-checks = true
+ "#)
+ .file("src/foo.rs", r#"
+ use std::panic;
+ pub fn main() {
+ let r = panic::catch_unwind(|| {
+ [1, i32::max_value()].iter().sum::<i32>();
+ });
+ assert!(r.is_err());
+ }"#);
+
+ assert_that(p.cargo_process("build").arg("--release"),
+ execs().with_status(0));
+ assert_that(&p.release_bin("foo"), existing_file());
+
+ assert_that(process(&p.release_bin("foo")),
+ execs().with_status(0).with_stdout(""));
+}
+
#[test]
fn cargo_test_verbose() {
let p = project("foo")